---
title: Configuration.pack()
api: Configuration.pack
---

## Description

<Summary/>

<FilterDiagram
  name="pack"
  input="Message x N"
  output="Message"
/>

The number of input _Messages_ to combine into one is given by the _batchSize_ parameter, which defaults to 1 if not presented.

You can set the maximum time interval between two consecutive batches coming out of a _pack_ filter by the _interval_ option in the _options_ parameter. It can be a number in seconds, or a string with a time unit suffix such as `'s'`, `'m'`, `'h'` or `'d'`. When _interval_ is greater than 0, a combined _Message_, if any, is always produced every time that interval has passed, no matter if _batchSize_ is reached or not.

### Defragmentation

A [Data](/reference/api/Data) object stores its bytes in an array of _4KB chunks_. After a series of _Data_ splitting and joining operations by codecs and scripts, the chunks stored in _Data_ will be fragmented and have unused spaces inside of them. The _pack_ filter has a side-effect to _defragment_ the chunks to save memory.

The degree of defragmentation can be controlled by the _vacancy_ option in the _options_ parameter. It tells the filter how much vacant space is allowed in every chunk, ranging from 0 where no vacancy should be kept, to 1 where no defragmentation is done at all. The default is 0.5, which means when a chunk has over half (2KB) space unused, it should be merged with its neighboring chunks.

Defragmentation does not change your code logic, it only saves memory consumption at the cost of extra memory move operations.

## Syntax

``` js
pipy()
  .pipeline()
  .pack()

pipy()
  .pipeline()
  .pack(batchSize)

pipy()
  .pipeline()
  .pack(
    batchSize,
    {
      vacancy,
      interval,
    }
  )
```

## Parameters

<Parameters/>

## See Also

* [Configuration](/reference/api/Configuration)
* [split()](/reference/api/Configuration/split)
